/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package memsim.instructions;

/**
 *
 * @author Joe
 * This class performs a 2's complement subtraction
 */
public class SUBS {
    
    public boolean overflow = false;

    /**
     *
     * @param op1  Operand1 for subtraction
     * @param op2  Operand2 for subtraction
     * @return     The result of op1 - op2 with the use of 2's complement arithmetic
     */

    public int subScalar(int op1, int op2){
		long result;
                long temp;
                UnsignedHelper uH = new UnsignedHelper();
                temp = uH.UnsignedLongFromInt(op2);
                temp = ~temp + 1;

                result = uH.UnsignedLongFromInt(op1) + temp;
                if (result > 0xFFFFFFFFL){
                    overflow = true;
                    result = 0;//need to handle this properly
                } else {
                    result = result & 0xFFFFFFFFL;
                }
		return (int)result;

	}

}
